<template>
    <el-row class="lives-news" id="articleList">
        <el-row>
            <el-col class="title">
                <h3>{{displayName}}</h3>
            </el-col>
        </el-row>

        <el-row>
            <el-form :inline="true" class="inline-form">
                <el-form-item>
                    <el-button @click="addConfig" type="primary"><i class="el-icon-edit el-icon--left"></i>修改</el-button>
                </el-form-item>
            </el-form>
        </el-row>
        <el-row>
            <el-col>
                <p>免责申明：{{value}}</p>
            </el-col>
        </el-row>
        <el-dialog :title="displayName" :visible.sync="addDialog" size="tiny" @close="cancelAddCategory" class="dialog">
                <el-form :model="msg" label-width="0">
                    <el-form-item>
                        <el-input type="textarea":rows="8" v-model="msg.value" auto-complete="off" :placeholder="'请输入' + displayName"></el-input>
                    </el-form-item>
                </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancelAddCategory">取 消</el-button>
                <el-button type="primary" @click="set">保 存</el-button>
            </div>
        </el-dialog>
    </el-row>
</template>
<script>
import {
    getConfig,
    setConfig
} from '@/api/api'
export default {
    data() {
        return {
        	canEmpty: true,
        	displayName: '免责申明',
        	key: 'disclaimer',
        	value: '',
            addDialog: false,
            value: '',
            msg: {
                value: ''
            }
        }
    },
    created() {
        getConfig(this.key).then(res => {
            console.log(res)
            this.value = res[this.key];
        })
    },
    methods: {
        set(){
            if(!this.canEmpty && !this.msg.value){
                this.$message({
                    type: 'error',
                    message: '请输入' + this.displayName
                })
                return;
            }
            
            var data = {}
            data[this.key] = this.msg.value
            
            setConfig(data).then(res => {
                console.log(res)
                this.value = this.msg.value;
                this.$message({
                    message: '操作成功',
                    type: 'success'
                })
                this.cancelAddCategory()
            })
        },
        addConfig: function(){
            this.addDialog = true;
            this.msg.value = this.value;
        },
        cancelAddCategory: function(){
            this.addDialog = false;
        }
    }
}
</script>
<style scoped lang="scss">
.lives-news {
    .title {
        font-size: 12px;
        border-bottom: 1px solid #eaeaea;
        margin-bottom: 5px;
        h3 {
            display: inline-block;
            padding: 5px 0;
            margin: 0;
            font-weight: normal;
            color: #23b7e5;
            border-bottom: 1px solid #23b7e5;
        }
    }
}
</style>